//
//  TM_GameHub.m
//  xGame
//
//  Created by Max on 11-10-29.
//  Copyright 2011年 __MyCompanyName__. All rights reserved.
//

#import "TM_GameHub.h"
#import "TM_GameLayer.h"

@implementation TM_GameHub
@synthesize gameLayer = _gameLayer;

-(id) init
{
    if ((self = [super init])) {
        CGSize winSize = [[CCDirector sharedDirector] winSize];
        
        label = [CCLabelTTF labelWithString:@"0" dimensions:CGSizeMake(50, 20)
                               alignment:UITextAlignmentRight fontName:@"Verdana-Bold" 
                                fontSize:18.0];
        label.color = ccc3(0,0,0);
        int margin = 10;
        label.position = ccp(winSize.width - (label.contentSize.width/2)- margin, label.contentSize.height/2 + margin);
        [self addChild:label];
        
        //Menu
        CCMenuItem *on;
        CCMenuItem *off;
        
        on = [[CCMenuItemImage itemFromNormalImage:@"projectile-button-on.png"
                                     selectedImage:@"projectile-button-on.png" target:nil selector:nil] retain];
        off = [[CCMenuItemImage itemFromNormalImage:@"projectile-button-off.png"
                                      selectedImage:@"projectile-button-off.png" target:nil selector:nil] retain];
        
        CCMenuItemToggle *toggleItem = [CCMenuItemToggle itemWithTarget:self
                                                               selector:@selector(projectileButtonTapped:) items:off, on, nil];
        CCMenu *toggleMenu = [CCMenu menuWithItems:toggleItem, nil];
        toggleMenu.position = ccp(100, 32);
        [self addChild:toggleMenu];
    }
    return self;
}

- (void)numCollectedChanged:(int)numCollected {
    [label setString:[NSString stringWithFormat:@"%d", numCollected]];
}

- (void)projectileButtonTapped:(id)sender
{
    if (_gameLayer.mode == 1) {
        _gameLayer.mode = 0;
    } else {
        _gameLayer.mode = 1;
    }
}

@end
